#!/usr/bin/env python2

#GoodFET MAXIM MAX3421 and MAX3420 Client
#by Travis Goodspeed

import sys;
import binascii;
import array;
import warnings

from GoodFETMAXUSB import GoodFETMAXUSB;

warnings.warn(
"""The libraries upon which this program depends will soon be
deprecated in favor of the USB*.py libraries.  See facedancer-umass.py
for an example of this program written using the new libraries."""
)

if(len(sys.argv)==1):
    print "Usage: %s verb [objects]\n" % sys.argv[0];
    print "%s info" % sys.argv[0];
    print "%s iotest" % sys.argv[0];
    print "%s peek 0x$start [0x$stop]" % sys.argv[0];
    print "%s poke 0x$adr 0x$val" % sys.argv[0];
    sys.exit();

#Initialize FET and set baud rate
client=GoodFETMAXUSB();
client.serInit()


client.MAXUSBsetup();

if(sys.argv[1]=="regs"):
    for adr in range(9,21): #*1024):
        val=client.rreg(adr);
        print "r%02i:=%02x" % (adr,val);
if(sys.argv[1]=="iotest"):
    while 1:
        client.wreg(20,client.rreg(20)>>4);
if(sys.argv[1]=="peek"):
    print "TODO";
if(sys.argv[1]=="poke"):
    print "TODO";
